package com.vecharm.app.utils

import android.app.Activity
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.support.v4.app.Fragment
import android.widget.ImageView
import com.ling.sdk.app.App
import com.ling.sdk.glide.GlideApp


fun ImageView.url(token: Any?, url: String?) = load(token, url).placeholder(ColorDrawable(Color.LTGRAY)).into(this)

fun ImageView.load(token: Any?, url: String?, defaultIcon: Int) = getGlide(token).load(url).defaultIcon(defaultIcon)

fun ImageView.load(token: Any?, url: String?) = getGlide(token).load(url)

fun getGlide(token: Any?) = when (token) {
    is Activity -> GlideApp.with(token)
    is Fragment -> GlideApp.with(token)
    else -> GlideApp.with(App.app)
}
